﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Configuration;
using System.IO;
using System.Xml.Serialization;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace BWClient
{
    public class BWClientDataManager
    {
        static string CurrentDic = System.AppDomain.CurrentDomain.BaseDirectory;
        public static string FileName = System.AppDomain.CurrentDomain.BaseDirectory + @"\" + "BWClientData.xml";
        public static string DesKey = "CtznxL839564178921";
        private static BWClientData getDefault()
        {
            return new BWClientData
            {
                BrainImageAnalysisConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CurrentDic + @"\BrainImageAnalysis.mdb;Persist Security Info=True",
                Directory = CurrentDic.Substring(0, CurrentDic.LastIndexOf(@"\")),
                DocDirectory = CurrentDic.Substring(0, CurrentDic.LastIndexOf(@"\")) + "Doc",
                HomePage = "http://106.3.45.131/cp/index.asp",
                Password = CommonHelper.DESEncode("123456", DesKey),
                UserName = CommonHelper.DESEncode("123456", DesKey),
                AutoLogin = false,
                iUserID = 0
            };
        }
        /// <summary>
        /// 获取当前系统配置信息
        /// </summary>
        /// <returns></returns>
        public static BWClientData getCurrentBWClientData()
        {
            if (File.Exists(FileName) == false)
            {
                SerializationHelper.Save(getDefault(), FileName);
            }

            BWClientData oBWClientData = new BWClientData();
            oBWClientData = (BWClientData)SerializationHelper.Load(oBWClientData.GetType(), FileName);
            return oBWClientData;
        }
    }
}
